const path=require('path')
var name = path.basename(__filename, '.js')//本文件名

var resolve = (recvStr) => {
    var arr = recvStr.split(',')
    var result = {}
    if (!arr | arr.length != 50) {
        console.log(arr.length)
        result.status = false
        result.msg = '数据长度错误'
    } else {
        result.status = true
        result.msg = 'ok'
        result.data = {}
        result.data.ch1value= arr[0]
        result.data.ch2value= arr[1]
        result.data.ch3value= arr[2]
        result.data.ch4value= arr[3]
        result.data.ch5value= arr[4]
        result.data.ch6value= arr[5]
        result.data.ch7value= arr[6]
        result.data.ch8value= arr[7]
        result.data.type= arr[8].trim()
        result.data.zeroValue1=arr[9]
        result.data.zeroValue2=arr[10]
        result.data.zeroValue3=arr[11]
        result.data.zeroValue4=arr[12]
        result.data.zeroValue5=arr[13]
        result.data.zeroValue6=arr[14]
        result.data.zeroValue7=arr[15]
        result.data.zeroValue8=arr[16]
        result.data.gainValue1=arr[17]
        result.data.gainValue2=arr[18]
        result.data.gainValue3=arr[19]
        result.data.gainValue4=arr[20]
        result.data.gainValue5=arr[21]
        result.data.gainValue6=arr[22]
        result.data.gainValue7=arr[23]
        result.data.gainValue8=arr[24]
        result.data.checkCycle=arr[25].trim()
        result.data.tolerance1=arr[26]
        result.data.tolerance2=arr[27]
        result.data.tolerance3=arr[28]
        result.data.tolerance4=arr[29]
        result.data.tolerance5=arr[30]
        result.data.tolerance6=arr[31]
        result.data.tolerance7=arr[32]
        result.data.tolerance8=arr[33]
        result.data.tolerance9=arr[34]
        result.data.tolerance10=arr[35]
        result.data.tolerance11=arr[36]
        result.data.tolerance12=arr[37]
        result.data.tolerance13=arr[38]
        result.data.tolerance14=arr[39]
        result.data.tolerance15=arr[40]
        result.data.tolerance16=arr[41]
        result.data.ch1level=arr[42].trim()
        result.data.ch2level=arr[43].trim()
        result.data.ch3level=arr[44].trim()
        result.data.ch4level=arr[45].trim()
        result.data.ch5level=arr[46].trim()
        result.data.ch6level=arr[47].trim()
        result.data.ch7level=arr[48].trim()
        result.data.ch8level=arr[49].trim()
        result.data.timeStamp=arr[50]
    }
    return result
}

var parserRule = (port) => {
    var Readline = require('@serialport/parser-readline')
    var ByteLength = require('@serialport/parser-byte-length')//指定数据帧字节长度，略
    var parser = port.pipe(new Readline({ delimiter: '\r\n' }))//以回车换行为结束标记
    return parser
}

module.exports = {
    name,
    parserRule,
    resolve
}